﻿# author:高金磊
# datetime:2021/11/12 16:08
import os
import time
from datetime import datetime
from Statics.Setting import *
import pytest

import Tools.SendEmail
from Tools.myPrint import *

if __name__ == '__main__':
    while(cycle_num!=0):
        cycle_num-=1
        myPrint_Hint("执行时间间隔为:",Interval_time[0],"天",Interval_time[1],"时",Interval_time[2],"分",Interval_time[3],'秒')
        time.sleep(((Interval_time[0]*24+Interval_time[1])*60+Interval_time[2])*60+Interval_time[3])
        report_time=str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        report_path="report\%s\gaodetestReport.html"%(report_time)
        print(report_path)
        report_path=report_path.replace(" ",'\\').replace(":","-")
        a=pytest.main([
                       # "-s",#未知问题,如果打印输出,报告中将无法获取输出和变量
                       "--html=%s"%(report_path),
                       "-vv",
                        # "-m weather"
                       ])
        res=""
        if a.value==0:#测试成功没有问题
            res="测试成功,运行返回值为:%s报告地址:%s"%(str(a),"M:\pycharm\softtesthomework\%s"%(report_path))
            myPrint_Success(res)
        else:
            res = "测试失败,运行返回值为:%s,请通过测试报告查看具体信息,报告地址:%s" %(str(a),"M:\pycharm\softtesthomework\%s"%(report_path))
            myPrint_Err(res)
        subject="高德接口自动化测试"+str(report_time)
        if Tools.SendEmail.mail(subject=subject, mail_msg=res):
            myPrint_Success("邮件发送成功")
        else:
            myPrint_Err("邮件发送失败，请检查邮件配置")